package com.ls.lserp.modules.setting.service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.Model;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;

import com.ls.lserp.common.persistence.Page;
import com.ls.lserp.common.service.CrudService;
import com.ls.lserp.common.utils.CollectionsUtils;
import com.ls.lserp.modules.common.entity.UploadFile;
import com.ls.lserp.modules.order.entity.Order;
import com.ls.lserp.modules.setting.dao.ConsumptionDao;
import com.ls.lserp.modules.setting.entity.Consumption;
import com.ls.lserp.modules.setting.entity.Ognization;
import com.ls.lserp.modules.setting.entity.Process;
import com.ls.lserp.modules.sys.utils.UserUtils;
import com.ls.lserp.modules.trade.entity.BookingOrders;



@Service
@Transactional(readOnly = true)
public class ConsumptionService extends CrudService<ConsumptionDao, Consumption>{

    @Autowired
    private ConsumptionDao consumptionDao;
    
    
    /**
     * @Title: findList
     * @Description: 一览查询
     * @param @param page
     * @param @param Size
     * @param @return
     * @return Page<Size> 
     * @throws
     */
   
   public Page<Consumption> findList(Page<Consumption> page, Consumption consumption) {
       
       // 设置分页参数
       consumption.setPage(page);
       
       // 执行分页查询
       page.setList(consumptionDao.findList(consumption));
       
       return page;
   }
    
   
   /**
    * @Title: saveSize
    * @Description: 保存尺码尺寸
    * @param @param size
    * @return void 
    * @throws
    */
  
  @Transactional(readOnly = false)
  public void saveConsumption(Consumption consumption) {
	  if (consumption.getSizeUnitCostId()==null){
	 		consumption.preInsert();
          if(consumption!=null) {
              consumptionDao.insert(consumption);
          }
	 		
		// 编辑
		}else{
			// 更新数据
/*          if(consumption.getConsumptionList()!=null){
          for(int i=0;i<consumption.getConsumptionList().size();i++){
              consumption.getConsumptionList().get(i).preUpdate();
              consumption.getConsumptionList().get(i).setRemarks(consumption.getRemarks());
              consumptionDao.update(consumption.getConsumptionList().get(i));
          }*/
          consumption.preUpdate();
          consumptionDao.update(consumption);
	    }

		// 判断list是否为空
		
  }
  /**
   * @Title: saveSize
   * @Description: 保存尺码尺寸
   * @param @param size
   * @return void 
   * @throws
   */
  
  @Transactional(readOnly = false)
  public void deleteConsumption(Consumption consumption) {
      // 编辑
      if(consumption.getSizeUnitCostId()!=null){
          
          consumption.preInsert();
          
          consumptionDao.deleteConsumption(consumption);
      }
  }
  
  /**
   * @Title: findSizeListChange
   * @Description: 
   * @param @param size
   * @param @return
   * @return List 
   * @throws
   */
 
 public Consumption consumptionShow(Consumption consumption){      
	 consumption = consumptionDao.consumptionShow(consumption);
     List<Consumption> conList = consumptionDao.findConsumptionList(consumption);
     consumption.setConsumptionList(conList);
     return consumption;
 }
 
 public String checkFlag(Consumption consumption){
     
     String checkFlag="";
     
     Consumption Consumption = new Consumption();
     
     Consumption= consumptionDao.checkFlag(consumption);
     
     if(Consumption!=null){
         
         checkFlag="1";
         
     }
     
     return checkFlag;
 }

//查询子项目
public List<Consumption> findConsumptionList(Consumption consumption) {
	
	return consumptionDao.findConsumptionList(consumption);
}

/**
 * @Title: findBrand
 * @Description: 查询
 * @param @param venderId
 * @param @return
 * @return List<InventoryRequest>
 * @throws
 */
public List<Consumption> findConsuList() {
   return consumptionDao.findConsuList();
}

/**
 * @Title: findBrand
 * @Description: 查询
 * @param @param venderId
 * @param @return
 * @return List<InventoryRequest>
 * @throws
 */
public List<Consumption> findConsuChildList(String consumptionCD) {
   return consumptionDao.findConsuChildList(consumptionCD);
}



  
  
}
